package com.person.ntv.service.sys.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.person.common.PageParams;
import com.person.exception.ServiceException;
import com.person.ntv.dao.sys.SysPropertyMapper;
import com.person.ntv.entity.sys.SysProperty;
import com.person.ntv.service.base.impl.BaseServiceImpl;
import com.person.ntv.service.sys.SysPropertyService;
@Service("sysPropertyService")
public class SysPropertyServiceImpl extends BaseServiceImpl<SysProperty> implements SysPropertyService{
	@Autowired
	private SysPropertyMapper sysPropertyMapper;
	@Autowired
	   public void setBaseMapper(){
		   super.setBaseMapper(this.sysPropertyMapper);
	   }
	
	@Override
	public Page<SysProperty> getSysProperties(PageParams pp)
			throws ServiceException {
		  try {
				PageHelper.startPage(pp.getPage(),pp.getRows(), pp.getOrderStr());
				return sysPropertyMapper.getSysProperties(pp.getParams());
			} catch (Exception e) {
				e.printStackTrace();
				throw new ServiceException("系统错误！");
			}
	}

	@Override
	public int deleteByPrimaryKeys(BigDecimal[] ids) throws ServiceException {
		try{
			int result=0;
		    for(BigDecimal id:ids){
		    	result+=deleteByPrimaryKey(id);
		    }
		    return result;
			}catch (Exception e) {
		          e.printStackTrace();
		          throw new ServiceException("系统错误。");
		  }
	}

	@Override
	public List<SysProperty> getSysAllProperties() throws ServiceException {
		 try {
				return sysPropertyMapper.getSysAllProperties();
			} catch (Exception e) {
				e.printStackTrace();
				throw new ServiceException("系统错误！");
			}
	}

	@Override
	public List<Map<String, Object>> getUserProperties(String userId)throws ServiceException {
		 try {
			 return sysPropertyMapper.getUserProperties(userId);
			} catch (Exception e) {
				e.printStackTrace();
				throw new ServiceException("系统错误！");
			}
	}

	@Override
	public int addUserProperty(Map<String, Object> map) throws ServiceException {
		try{
			int result=0;
			result=sysPropertyMapper.addUserProperty(map);
		    return result;
			}catch (Exception e) {
		          e.printStackTrace();
		          throw new ServiceException("系统错误。");
		  }
	}
}
